package com.hsjk.szwj.module.pay.service;

import com.hsjk.szwj.framework.common.constant.CommonConstant;
import com.hsjk.szwj.module.pay.constant.PayOrderConstant;
import com.hsjk.szwj.module.pay.dal.dataobject.config.MchAppConfigContext;
import com.hsjk.szwj.module.pay.controller.app.order.vo.UnifiedOrderReqVO;
import com.hsjk.szwj.module.pay.dal.dataobject.order.PayOrderDO;
import com.hsjk.szwj.module.pay.util.ChannelCertConfigKitBean;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;

/**
 * @author chenjiawei
 * @desc 支付接口抽象类
 * @Date 2023/08/23 22:36
 **/
public abstract class AbstractPaymentService implements IPaymentService {
    //    @Autowired
//    protected SysConfigService sysConfigService;
    @Resource
    protected ChannelCertConfigKitBean channelCertConfigKitBean;
    @Resource
    protected ConfigContextQueryService configContextQueryService;
    @Value("${szwj.pay.base-url}")
    private String payBaseUrl;

    @Override
    public String customPayOrderId(UnifiedOrderReqVO bizRQ,
                                   PayOrderDO payOrder, MchAppConfigContext mchAppConfigContext) {
        //使用系统默认支付订单号
        return null;
    }

    /**
     * 订单分账（一般用作 如微信订单将在下单处做标记）
     */
    protected boolean isDivisionOrder(PayOrderDO payOrder) {
        //订单分账， 将冻结商户资金。
        if (payOrder.getDivisionMode() != null
                && (PayOrderConstant.DIVISION_MODE_AUTO == payOrder.getDivisionMode()
                || PayOrderConstant.DIVISION_MODE_MANUAL == payOrder.getDivisionMode())) {
            return true;
        }
        return false;
    }

    protected String getNotifyUrl() {
        return payBaseUrl + "/app-api/pay/callback/" + getIfCode();
    }

    protected String getNotifyUrl(String payOrderId) {
        return payBaseUrl + "/app-api/pay/callback/" + getIfCode() + "/" + payOrderId;
    }

    protected String getReturnUrl() {
        return payBaseUrl + "/api/pay/return/" + getIfCode();
    }

    protected String getReturnUrl(String payOrderId) {
        return payBaseUrl + "/app-api/pay/return/" + getIfCode() + "/" + payOrderId;
    }

    protected String getReturnUrlOnlyJump(String payOrderId) {
        return payBaseUrl + "/app-api/pay/return/" + getIfCode() + "/"
                + CommonConstant.PAY_RETURNURL_FIX_ONLY_JUMP_PREFIX + payOrderId;
    }
}
